<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>提醒通知</title>
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/dataTables/css/jquery.dataTables.min.css"/>
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">

<style> 
        .caoZuo{font-size: 15px;margin: 0 4px;color:#1ab394}
</style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-content" style="margin-bottom: 15px;">
            <span id="count" class="text-navy" style="font-size:22px;">3</span><span style="font-size: 16px;">个通知</span>
             <shiro:hasPermission name="notice_reminding_add">
                 <button onclick="window.location.href='<%=path%>/view/ui/createNotice?type=create'" class="btn btn-primary" type="button" style="float:right;">新增通知</button>
             </shiro:hasPermission>
            <shiro:hasPermission name="notice_reminding_set">
                <button class="btn btn-primary" type="button" style="float:right;margin-right: 10px;" data-toggle="modal" data-target="#myModalNotice" onclick="noticeSetBtn();" >通知设置</button>
            </shiro:hasPermission>
        </div>
        <div class="ibox-content">
            <table class="display  table-striped table-bordered table-hover" id="mydataTable">
                <thead>
                    <tr>
                       <th>通知名称</th>
                        <th>通知类型</th>
                        <th>通知手机号</th>
                        <th>通知次数(定时任务)</th>
                        <th>通知次数</th>
                        <th>备注</th>
                        <th>操作列</th>
                    </tr>
                </thead>
                <tbody>
                   
                </tbody>
            </table>
        </div>

        <!-- 通知设置 -->
        <div  hidden="" class="modal inmodal fade" id="myModalNotice" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-sm" style="width:500px;">
                <div class="modal-content">
                    <div class="modal-header" style="padding: 15px 15px 10px;">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="text-left">通知设置</h4>
                    </div>
                    <div class="text-center" style="width:100%;height:250px;">
                        <form method="get" class="form-horizontal col-sm-12" style="margin:60px 0;">
                            <div class="form-group">
                                <div class="col-sm-4" style="padding-top: 5px;text-align: right;">
                                    <span style="font-size:15px;">短信余量提醒</span>
                                </div>
                                <div class="col-sm-5" style="text-align: left;">
                                   <input id="yltsNum" maxlength="10" class="form-control" disabled="disabled" placeholder="请填写余量条数">
                                </div>
                                <div class="col-sm-3" style="text-align: left;">
                                    <img id="noticeEdit" title="编辑" onclick="noticeSet();" style="cursor:pointer;" src="${pageContext.request.contextPath}/images/system/notice_edit.png">
                                    <img id="noticeConfirm" title="确认" onclick="noticeAdd();" style="cursor:pointer;display:none;" src="${pageContext.request.contextPath}/images/system/notice_confirm.png">
                                    <img id="noticeCancel" title="取消" onclick="noticeQx();" style="cursor:pointer;display:none;" src="${pageContext.request.contextPath}/images/system/notice_cancel.png">
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>


        <!-- 删除部门 -->
        <div  hidden="" class="modal inmodal fade" id="myModalDelete" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-sm" style="width:500px">
                <div class="modal-content">
                    <div class="modal-header" style="padding: 15px 15px 10px;">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="text-left">删除部门</h4>
                    </div>
                    <div class="text-center" style="width:100%;height:60px;">
                        <form method="get" class="form-horizontal col-sm-12" style="margin:20px 0;">
                            <div class="form-group">
                                <div class="col-sm-12">
                                    <span>删除后将不会对手机号进行提醒，确定删除吗？</span>
                                </div>
                            </div>

                        </form>
                    </div>
                    <div class="modal-footer" style="text-align:center;border-top:none;">
                        <button type="button" class="btn btn-outline btn-primary" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary k_verify" onclick="delNotice()">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    
    <script type="text/javascript" src="<%=path%>/hplus/js/plugins/dataTables/jquery.dataTables.min.js"></script>
    <script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>

    <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script type="text/javascript" src="<%=path%>/js/system/menuJump.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	
    <script type="text/javascript">
    var path = "<%=path%>";
    var myDataTable;
   	var id;
   	var count;
    $(function(){
    	init();
    });
    
    function init(){
    	myDataTable = dataTable();
    }
    
    function func_dataTableReload(){
    	myDataTable.ajax.reload(function(){
    		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
    		$('input').iCheck('uncheck');
    	});
    }
    
    
    function dataTable(){
    	return $('#mydataTable').DataTable({
    		processing: true,
    		ordering: false,
    		searching: false,
    		info: true,
    		autoWidth: true,
    		lengthChange: false,
    		"order": [[ 2, "desc" ]],
    	    language: {
    	    	emptyTable: '<div id="content_empty"  class="form-group white-bg" style="text-align:center;padding:200px 0;margin:0;">   <p>暂无数据</p></div>',
    	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
    			infoEmpty: '没有数据',
    			lengthMenu: '每页显示 _MENU_ 条记录',
    			loadingRecords: '正在加载数据....',
    			processing: '正在处理数据....',
    			zeroRecords: '没有找到匹配的记录',
    			paginate: {
    				first: '首页',
    				previous: '前页',
    				next: '后页',
    				last: '尾页'
    			}
    	    },
    	    order: [[1,'desc']],
    		pageLength: 10,
    	    pagingType: 'full_numbers',
    	    columnDefs: [
                {
                    render: function(data, type, full) {
                        var result = "";
                        if(data == 1){
                            result = '短信余额不足';
                        }
                        return result;
                    },
                    targets: 1
                }, {
                    render: function(data, type, full) {
                        var result = "";
                        if(data.length > 18){
                            result = '<span title="'+data+'">'+ data.substring(0,18)+'...</span>';
                        }else{
                            result = data;
                        }
                        return result;
                    },
                    targets: 2
                },{
                    render: function(data, type, full) {
                        var result = "";
                        if(data == 0){
                            result +="-";
                        }else {
                            result += data + "次";
                        }
                        return result;
                    },
                    targets: 3,
                    visible: false
                },{
                    render: function(data, type, full) {
                        var result = "";
                        if(data == 0){
                            result +="-";
                        }else {
                            result += data + "次";
                        }
                        return result;
                    },
                    targets: 4
                },
                {
                    render: function(data, type, full) {
                        var result = data;
                        return result;
                    },
                    targets: 5,
                    visible: false
                },
    	        {
    			render: function(data, type, full) {
    				var result = "";
    				//编辑角色纳入shiro权限控制
    				result += '<shiro:hasPermission name="notice_reminding_edit">';
    				result += '<a batchId="'+data+'"  class="caozuo edit" href="<%=path%>/view/ui/editNotice?type=edit&id='+data+'&phones='+full.smsNoticePhone+'&name='+full.name+'&remark='+full.remarks+'&smsNoticeTypeId='+full.smsNoticeTypeId+'">编辑</a>';
    				result += '</shiro:hasPermission>';
    				//删除角色纳入shiro权限控制
    				result += '<shiro:hasPermission name="notice_reminding_delete">';
    				result += '<a batchId="'+data+'"  class="caozuo delete" onclick="javascript:deletedDialog(\''+data+'\');">删除</a>';
    				result += '</shiro:hasPermission>';
                    return result;
                },
    			targets: 6
    		}],
    	    columns: func_columns(),
    	    serverSide: true,
    	    ajax: {
    	    	contentType: 'application/json;charset=utf-8',
    	    	type: 'POST',
    	    	url: func_AjaxUrl(),
    	    	data: function(d){
    	    		//d.cid=cid;
    				return JSON.stringify(d);
    			}
    		}
    	}).on( 'draw', function () {
    		var info=myDataTable.page.info(); 
        	$('#count').html(info.recordsTotal);

    	} );
    	
    }

    function func_AjaxUrl(){
    	 return path+"/smsNotice/ajaxPageData";
    }
    /**		
     *	设置列名，对应后台
     */
    function func_columns(){
    	var jsonArr = [
    		{"data":"name"},
    		{"data":"smsNoticeTypeId"},
    		{"data":"smsNoticePhone"},
            {"data":"smsNoticeNum"},
            {"data":"smsNoticeNumTotal"},
            {"data":"remarks"},
    		{"data":"id"},
    	];
    	return jsonArr;
    }



    //通知设置
    function noticeSet(){
        $("#noticeEdit").hide();
        $("#noticeConfirm").show();
        $("#noticeCancel").show();
        $("#yltsNum").attr("disabled",false);
        $("#yltsNum").val($("#yltsNum").val().replace("不足",""));
    }

    //确认修改短信余量
    function noticeAdd() {
        //正则表达式，判断必须是数字
        var reg = /^[0-9]*$/;

        if($("#yltsNum").val() == null || $("#yltsNum").val() == ""){
            errorDialog("请填写短信余量阀值");
            return;
        }else if(!reg.test($("#yltsNum").val())){
            errorDialog("短信余量阀值必须为数字");
            return;
        }else if($("#yltsNum").val().substring(0,1) == 0){
            errorDialog("请填写正确的短信阈值");
            return;
        }else {
            var url = "<%=path%>/company/ajaxUpdateCompanyInfo";
            $.post(url, {
                "smsThreshold": $("#yltsNum").val()
            }, function (data) {
                var realData = data.data;
                if (data.status == 200) {
                    $("#yltsNum").val("不足" + $("#yltsNum").val());
                    $("#noticeEdit").show();
                    $("#noticeConfirm").hide();
                    $("#noticeCancel").hide();
                    $("#yltsNum").attr("disabled", true);
                } else {
                    errorDialog(data.message);
                }
            });
        }

    }

    //取消修改短信余量
    function noticeQx() {
        noticeSetBtn();
        $("#noticeEdit").show();
        $("#noticeConfirm").hide();
        $("#noticeCancel").hide();
        $("#yltsNum").attr("disabled",true);

    }

    //点击通知设置的按钮,发送ajax请求
    function noticeSetBtn(){
        var url="<%=path%>/company/ajaxCompanyInfo";
        $.post(url, {
        }, function(data) {
            var realData = data.data;
            if (data.status == 200) {
                $("#yltsNum").val("不足"+realData.smsThreshold);
            }else{
                errorDialog(data.message);
            }
        });
    }
    var delId = '';
    //删除通知弹窗
    function deletedDialog(data){
        $("#myModalDelete").modal('show');
        delId = data;
    }

    //逻辑删除通知ajax请求
    function delNotice(){
        var url=path+"/smsNotice/ajaxDelete"
        $.post(url, {
            "id" : delId
        }, function(data) {
            if (data.status == 200) {
                func_dataTableReload();
                successDialog("删除成功");
                $("#myModalDelete").modal('hide');
            }else {
                errorDialog("删除失败");
            }
        });


    }
    </script>
</body>
</html>
